<?php
 
//数据库连接
require("connectsql.php");

//从注册页接受来的数据
$user=$_POST["username"];
$pwd=$_POST["password"];

$sql="INSERT INTO user (username,password) VALUES ('$user','$pwd')";
$select="SELECT username FROM user WHERE username='$user'";
$result=mysqli_query($conn,$select);
$row=mysqli_num_rows($result);

if(!$row){

    if (mysqli_query($conn,$sql)){
        echo "<script>alert('注册成功，请登录');location='login.html'</script>";
    }else{
        echo "<script>alert('注册失败，请重新注册');location='regsiter.html'</script>";
    }

}else{
    echo "<script>alert('该用户已经存在，请直接登录');location='login.html'</script>";
}
?>